﻿<%@ WebHandler Language="C#" Class="CM_MemAdd" %>

using System;
using System.Web;
using Chain.Common;
using Chain.Common.DEncrypt;
using System.Security.Cryptography;

public class CM_MemAdd : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string tel = context.Request["tel"].ToString() == "" ? "" : context.Request["tel"];
        string name = context.Request["name"].ToString() == "" ? "" : context.Request["name"];
        string focus = context.Request["focus"].ToString() == "" ? "-1" : context.Request["focus"].ToString();//0 已关注，-1 未关注            
        string openid = context.Request["openid"].ToString() == "" ? "" : context.Request["openid"];
        string key = context.Request["key"].ToString().Trim() == "" ? "" : context.Request["key"].ToString().Trim();

        int flag = CM_AddMem(tel, name, focus, openid, key);
        context.Response.Write( "jsonpcallback('"+flag+"')");
    }


    public int CM_AddMem(string tel, string name, string focus, string openid, string key)
    {
        int flag = 0;

        int scenestr = 0;
        string secret = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile((tel + "MemAdd"), "MD5").Trim().ToLower();
        if (key == secret)
        {
            if (string.IsNullOrEmpty(tel) || tel == "" || tel.Length != 11 )
            {

                flag = -1;
            }
            else
            {
                Chain.Model.MicroWebsiteSceneStr websitescenestr = new Chain.Model.MicroWebsiteSceneStr();
                websitescenestr = new Chain.BLL.MicroWebsiteSceneStr().GetModel(openid);
                if (websitescenestr != null)
                {
                    scenestr = websitescenestr.SceneStr;
                }
                else
                {
                    scenestr = 1;
                }

                Chain.BLL.Mem memBll = new Chain.BLL.Mem();
                flag = memBll.WeiXinRegister(name, "E62A9E6C1892C6BB", tel, "0", openid, scenestr, focus);

            }
        }
        else
        {
            flag = -2;

        }
        return flag;
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}